// 云函数入口文件
const cloud = require('wx-server-sdk')
const axios = require('axios')
cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
    const { APIKEY, SECKEY } = event;
    const tokenUrl = `https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=${APIKEY}&client_secret=${SECKEY}`;
    const { data } = await axios({
        url: tokenUrl,
        method: 'POST',
        dataType: 'json',
        header: {
            'content-type': 'application/json; charset-UTF-8'
        },
    });
    const { access_token } = data;
    return access_token;
}